/**
 * 主页面的侧边栏
 * Created by yuzhou on 16/9/21.
 */

define([
    'vue','debug', 'text!tpl/mainSideBar.html',
    'components/mainSideBarMenu',
    'vuex/actions/user'
], function(Vue, Debug, mainSideBarHtml, MainSideBarMenu, userAction) {

    var debug = Debug('App:Main:SideBar')

    Vue.component('main-side-bar-menu', MainSideBarMenu)

    return Vue.extend({
        template: mainSideBarHtml,
        vuex: {
            getters: {
                tree: function(store){ return store.user.tree }
            },
            actions: {
                getUserModuleTree: userAction.getUserModuleTree,
                updateTreeByPath: userAction.updateTreeByPath
            }
        },
        components: {
        },
        ready: function(){
            debug('Main SideBar component is ready')
            var vm = this
            window.router.afterEach(function (transition) {
                vm.updateTreeByPath(transition.to.path)
            })
            vm.getUserModuleTree(function(){
                vm.updateTreeByPath(window.router._currentRoute.path)
            })
        }
    })
})
